package leecode

func numSubarraysWithSum(nums []int, goal int) (result int) {
	hashMap := make(map[int]int) //存储前缀和
	sum := 0
	for _, num := range nums {
		//一直累加
		sum += num
		if sum == goal {
			result++
		}
		result = result + hashMap[sum-goal]
		hashMap[sum] = hashMap[sum] + 1
	}
	return
}
